package cn.edu.njust.service.impl;

import cn.edu.njust.mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import cn.edu.njust.pojo.User;
import cn.edu.njust.service.LoginService;
import cn.edu.njust.util.SqlSessionFactoryUtils;

public class LoginServiceImpl implements LoginService {
    // 获取工厂对象
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    /**
     * @param user - 登录用户
     * @return 用户实例
     */
    @Override
    public User loginResult(User user) {
        // 获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        // 获取mapper
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        // 调用方法
        User user1 = mapper.selectById(user);

        sqlSession.close();

        return user1;
    }

    @Override
    public int queryIdentity(User user) {
        return user.getIdentity();
    }

    @Override
    public int queryStatus(User user) {return user.getStatus();}
}
